home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 June
/
Macworld (1999-06).dmg
/
Shareware World
/
Info
/
For Developers
/
MacZoop2.0.sea
/
MacZoop2.0
/
Required Classes
/
ZComrade.h
< prev
next >
Wrap
Text File
|
1999-02-11
|
3KB
|
94 lines
/*************************************************************************************************
*
*
* MacZoop - "the framework for the rest of us"
*
*
*
* ZComrade.h -- an object that can maintain loose links between objects
*
*
*
*
*
* © 1996, Graham Cox
*
*
*
*
*************************************************************************************************/
#pragma once
#ifndef __ZCOMRADE__
#define __ZCOMRADE__
#include "ZObject.h"
class ZComrade;
class ZMessage;
class ZComradeList;
// set up streaming stuff:
DEFINECLASSID( ZComrade, 'zcom' );
// class def:
class ZComrade : public ZObject
{
private:
ZComradeList* talkers;
ZComradeList* listeners;
public:
ZComrade();
virtual ~ZComrade();
virtual void SendMessage( long aMessage, void* msgData );
virtual void SendMessage( ZMessage* aMessage );
virtual void ReceiveMessage( ZComrade* aSender, long theMessage, void* msgData ) {};
virtual void ReceiveMessage( ZComrade* aSender, ZMessage* aMessage ) {};
virtual void ListenTo( ZComrade* aSender );
virtual void StopListeningTo( ZComrade* aSender );
// streaming:
virtual void WriteToStream( ZStream* aStream );
virtual void ReadFromStream( ZStream* aStream );
protected:
virtual void AddTalker( ZComrade* aTalker );
virtual void AddListener( ZComrade* aListener );
virtual void RemoveTalker( ZComrade* aTalker );
virtual void RemoveListener( ZComrade* aListener );
};
/*
What are comrades for? If you are familiar with TCL or another framework, this is like a
collaborator. It allows objects to communicate through a standard interface (the comrade
interface) without the objects needing to know explicitly what the various talkers and
listeners actually are- in other words, it is a loose binding between objects.
Comrades are very useful- for example if you want two windows to represent some common data,
you can make both windows become listeners of the data object. The data transmits a message
when it changes, and both windows can update their views accordingly. Thus problems with
keeping duplicates of the data disappear.
In MacZoop, many objects are subclassed from ZComrade- all Commanders, windows, arrays, etc
are comrades. Use the "Show Hierarchy Window" command in CodeWarrior to see how everything
fits together. Neat, huh?
Note:- ZMessage is currently not actually declared anywhere, thus leaving it up to the
user/programmer of MacZoop to implement whatever is needed. This may change in the future.
*/
#endif